<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>payment</title>
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <form class="layui-form" action="" style="padding:20px;">
            <div style="text-align: center;margin: 10px 10px 20px 30px;line-height: 50px">
                <label class="layui-row" id="balance" style="font-family: 'Agency FB'; font-size: 20px; color: #000000">医保余额:</label>
            </div>

        </form>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs data-count-sel" lay-event="sel">退款</a>
        </script>

    </div>
</div>

<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['table', 'form'], function () {
        //开始使用

        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            layuimini = layui.layuimini;


        var userInfo = layui.data('userInfo');
        $.ajax({
            url: "http://localhost:8080/dyx_people/balance?token="+userInfo.token,    //请求的url地址
            dataType: "json",   //返回格式为json
            async: true,//请求是否异步，默认为异步，这也是ajax重要特性
            data: {"id": "value"},    //参数值
            type: "GET",   //请求方式
            beforeSend: function () {
                //请求前的处理
            },
            success: function (res) {
                $('#balance').html("医保余额 :" + res.data);
            },
            complete: function () {
                //请求完成的处理
            },
            error: function () {
                //请求出错处理
            }
        });


        //加载所有账单
        table.render({
            elem: '#currentTableId',
            url: 'http://localhost:8080/dyx_people/paymentList?token='+userInfo.token,
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'paymentid', width: 80, title: 'ID', sort: true},
                {field: 'peopleaccent', width: 200, title: '账户'},
                {field: 'druginformation', width: 200, title: '订单信息'},
                {field: 'totalpay', width: 200, title: '总花费'},
                {field: 'paytime', width: 500, title: '支付时间'},
                {title: '操作', width: 150, templet: '#currentTableBar', fixed: "right", align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true
        });


        //退款
        table.on('tool(currentTableFilter)', function (obj) {
            if (obj.event === 'sel') {
                var data = obj.data;  //得到修改后的值
                $.ajax({
                    url:'http://localhost:8080/dyx_people/fundBack?paymentid='+data['paymentid'],
                    method:'get',
                    data:data.field,
                    dataType:'JSON',
                    success:function(res){
                        if(res.code==='0'){
                            parent.closeIframe("退款成功!");
                        }
                        else
                            alert(res['msg']);
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("退款失败!");
                    }
                }) ;
                table.reload('currentTableId', {
                }, 'data');
                return false;
            }
        });


    });
</script>
</body>
</html>